home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / src-16f.lha / tools / chop.c < prev    next >
C/C++ Source or Header  |  1992-01-24  |  725b  |  49 lines

  1. #include <stdio.h>
  2.  
  3. #define BUFFERSIZE (1<<21)
  4.  
  5. char buffer[BUFFERSIZE];
  6.  
  7. void chop(infile)
  8. char *infile;
  9. {
  10.     FILE *in, *out;
  11.     char outfile[1024];
  12.     int count, bytes;
  13.  
  14.     count = 0;
  15.  
  16.     in = fopen(infile, "r");
  17.     if (in == NULL) {
  18.     perror(infile);
  19.     return;
  20.     }
  21.  
  22.     while ((bytes = fread(buffer, 1, BUFFERSIZE, in)) != 0) {
  23.     sprintf(outfile, "%s.%d", infile, count++);
  24.     out = fopen(outfile, "w+");
  25.     if (out == NULL) {
  26.         perror(outfile);
  27.         fclose(in);
  28.         return;
  29.     }
  30.     fwrite(buffer, 1, bytes, out);
  31.     fclose(out);
  32.     }
  33.  
  34.     fclose(in);
  35. }
  36.  
  37. main(argc, argv)
  38. int argc;
  39. char *argv[];
  40. {
  41.     if (argc < 2) {
  42.     fprintf(stderr, "usage: chop file...\n");
  43.     exit(1);
  44.     }
  45.  
  46.     while (*++argv != NULL)
  47.     chop(*argv);
  48. }
  49.